/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author wei
 */
@Entity
public class StackUser implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String email;
    private String stackId;
    
    @OneToMany
    private Collection<StackUser> following = new HashSet<StackUser>();

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getStackId() {
        return stackId;
    }

    public void setStackId(String stackId) {
        this.stackId = stackId;
    }

    public Collection<StackUser> getFollowing() {
        return following;
    }

    public void setFollowing(Collection<StackUser> following) {
        this.following = following;
    }
    
    public String getFollowingToString(){
        StringBuilder resBuilder = new StringBuilder();
        for(StackUser u : getFollowing()){
            resBuilder.append(u.stackId).append(";");
        }
        
        return resBuilder.substring(0, resBuilder.length()-1);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof StackUser)) {
            return false;
        }
        StackUser other = (StackUser) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "StackUser{" + "id=" + id + ", email=" + email + ", stackId=" + stackId + ", following=" + following.size() + '}';
    }
    
}
